package rs.dalao.syc.doctor.prescription.dao.persist.repository.impl;/*
 *   @author:Casin
 *   @date:2023/8/12
 *   @code:
 */


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import rs.dalao.syc.common.pojo.vo.PageData;
import rs.dalao.syc.common.util.PageInfoToPageDataConverter;
import rs.dalao.syc.doctor.prescription.dao.persist.mapper.PrescriptionMapper;
import rs.dalao.syc.doctor.prescription.dao.persist.repository.IPrescriptionRepository;
import rs.dalao.syc.doctor.prescription.pojo.entity.Prescription;
import rs.dalao.syc.doctor.prescription.pojo.vo.PatientListVO;
import rs.dalao.syc.doctor.prescription.pojo.vo.PatientNameVO;

import java.util.List;

@Repository
@Slf4j
public class PrescriptionRepository implements IPrescriptionRepository {
    @Autowired
    PrescriptionMapper mapper;

    @Override
    public int addNew(Prescription prescription) {
        return mapper.insert(prescription);
    }

    @Override
    public int update(Prescription prescription,Long id) {
        QueryWrapper<Prescription> wrapper=new QueryWrapper<>();
        wrapper.eq("id",id);
        return mapper.update(prescription,wrapper);
    }

    @Override
    public List<PatientNameVO> getAllPatient() {
        return mapper.getAllPatient();
    }

    @Override
    public PageData<PatientListVO> getPatientList(Long doctorId, Integer pageNum, Integer pageSize) {
        log.debug("开始执行【查询用户列表】的数据访问，页码：{}，每页记录数：{}", pageNum, pageSize);
        PageHelper.startPage(pageNum, pageSize);
        List<PatientListVO> list = mapper.getPatientList(doctorId);
        PageInfo<PatientListVO> pageInfo = new PageInfo<>(list);
        return PageInfoToPageDataConverter.convert(pageInfo);
    }
}
